#!/bin/bash
export PATH=$PATH:/home/linux_7210764212/jdk8/jdk1.8.0_202/bin:/home/linux_7210764212/tomcat8/apache-tomcat-8.5.96/bin
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
TOMCAT_PATH='/home/linux_7210764212/tomcat8/apache-tomcat-8.5.96'
EXAM_PATH='/home/linux_7210764212/Exam12'

# get classpath
CP=${TOMCAT_PATH}/lib/servlet-api.jar

# 题目1
# 使用for循环，将webapps/ROOT/WEB-INF/lib下的所有jar包的文件名一一取出
# 并追加到变量CP中
t=${TOMCAT_PATH}/webapps/ROOT/WEB-INF/lib/
for file in `ls ${TOMCAT_PATH}/webapps/ROOT/WEB-INF/lib/`
do
CP=${CP}:${t}$file
done

# compile
javac -classpath $CP ${EXAM_PATH}/code/*.java -d ${EXAM_PATH}/target

if [ $? -ne 0 ]
then
   echo 'complie error'
   exit
fi

# 题目2
# 删除目录 webapps/ROOT/WEB-INF/classes 下的所有class文件
# 将target目录下的所有class文件 移动到 webapps/ROOT/WEB-INF/classes中

rm -rf ${TOMCAT_PATH}/webapps/ROOT/WEB-INF/classes/*.class
mv ${EXAM_PATH}/target/*.class ${TOMCAT_PATH}/webapps/ROOT/WEB-INF/classes

# 题目3
# 重启tomcat
bash ${TOMCAT_PATH}/bin/shutdown.sh
bash ${TOMCAT_PATH}/bin/startup.sh
